<template>
  <div id="furtherEdu" class="box-body">
    <div class="box box-primary">
      <div class="box-header with-border">
        <h3 class="box-title">继续教育情况</h3>
        <div class="box-tools pull-right">
          <el-button type="success" class="btn btn-success" v-if='isEditable'  @click="editVisiable = true">
            <i class='fa fa-plus-square-o'>添加继续教育</i>
          </el-button>
        </div>
      </div>
      <div class="box-body">
        <div class=" form-inline dt-bootstrap" id="example1_wrapper">
          <div class="row">
            <div class="col-sm-12 table-responsive">
              <table class="table table-hover table table-bordered table-striped dataTable">
                <tbody>
                  <tr>
                    <th aria-label="学历种类" style="width: 142px;" colspan="1" rowspan="1" aria-controls="tblresumes" tabindex="0" class="sorting">学历种类</th>
                    <th aria-label="学历（学位）层次" style="width: 101px;" colspan="1" rowspan="1" aria-controls="tblresumes" tabindex="0" class="sorting">学历（学位）层次</th>
                    <th aria-label="录取院校" style="width: 182px;" colspan="1" rowspan="1" aria-controls="tblresumes" tabindex="0" class="sorting">录取院校</th>
                    <th aria-label="进修专业" style="width: 142px;" colspan="1" rowspan="1" aria-controls="tblresumes" tabindex="0" class="sorting">进修专业</th>
                    <th aria-label="学制（年）" style="width: 101px;" colspan="1" rowspan="1" aria-controls="tblresumes" tabindex="0" class="sorting">学制（年）</th>
                    <th aria-label="毕业证书号码" style="width: 181px;" colspan="1" rowspan="1" aria-controls="tblresumes" tabindex="0" class="sorting">毕业证书号码</th>
                    <th aria-label="学位证书号码" style="width: 181px;" colspan="1" rowspan="1" aria-controls="tblresumes" tabindex="0" class="sorting">学位证书号码</th>
                    <th v-if='isEditable' aria-label="操作" style="width: 101px;" colspan="1" rowspan="1" aria-controls="tblresumes" tabindex="0" class="sorting">操作</th>
                  </tr>
                  <tr :key="index" v-for='(value,index) in this.educations' role="row" class="value.cls">
                    <td class="text-light" v-text="getcategoryname(value.category)"></td>
                    <td class="text-light" v-text="getdegreename(value.degree)"></td>
                    <td>{{ value.school }}</td>
                    <td>{{ value.discipline }}</td>
                    <td>{{ value.years }}</td>
                    <td>{{ value.graduationNo }}</td>
                    <td>{{ value.degreeNo }}</td>
                    <td v-if='isEditable'>
                      <div class="col-md-2">
                        <button @click="deletetrain(index)" class="btn btn-xs">删除</button>
                      </div>
                    </td>
                  </tr>
                </tbody>
              </table>
            </div>
          </div>
        </div>
      </div>
      <!-- <b-modal id='modalfurtedu' title='新增继续教育信息' close-title='关闭' ok-title='保存' @ok='submit' @shown='clearEditData'> -->
      <el-dialog title="新增继续教育信息" :visible.sync="editVisiable" :modal="false" size="small">
        <div class="form-horizontal">
          <div class="box-body">
            <div class="form-group">
              <label class="col-md-2 control-label my-label">学历种类</label>
              <div class="col-sm-4">
                <select v-model="editeducation.category" class="form-control">
                  <option :key="option.id" v-for="option in this.educategorylist" v-bind:value="option.id">{{ option.name }}</option>
                </select>
              </div>
              <label class="col-md-2 control-label my-label">学历（学位）层次</label>
              <div class="col-sm-4">
                <select v-model="editeducation.degree" class="form-control">
                  <option :key="option.id" v-for="option in this.degrees" v-bind:value="option.id">{{ option.name }}</option>
                </select>
              </div>
            </div>
            <div class="form-group">
              <label class="col-md-2 control-label my-label">录取院校</label>
              <div class="col-sm-4">
                <input class="form-control" v-model="editeducation.school" placeholder="请输入录取院校">
              </div>
              <label class="col-md-2 control-label my-label">进修专业</label>
              <div class="col-sm-4">
                <input class="form-control" v-model="editeducation.discipline" placeholder="请输入进修专业">
              </div>
            </div>
            <div class="form-group">
              <label class="col-md-2 control-label my-label">学制（年）</label>
              <div class="col-sm-4">
                <input class="form-control" v-model="editeducation.years" placeholder="请输入学制（年）">
              </div>
              <label class="col-md-2 control-label my-label">毕业证书号码</label>
              <div class="col-sm-4">
                <input class="form-control" v-model="editeducation.graduationNo" placeholder="请输入毕业证书号码">
              </div>
            </div>
            <div class="form-group">
              <label class="col-md-2 control-label my-label">学位证书号码</label>
              <div class="col-sm-4">
                <input class="form-control" v-model="editeducation.degreeNo" placeholder="请输入学位证书号码">
              </div>
            </div>
          </div>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="editVisiable = false">关 闭</el-button>
          <el-button type="primary" @click="submit">确 定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>
<script>
import MyDatePicker from '../../mycomponents/common/MyDatePicker'
export default {
  name: 'FurtherEdu',
  props: ['educations', 'editable'],
  data: function() {
    return {
      // educations: [],
      isEditable: true,
      editVisiable: false,
      editeducation: {
        category: 1,
        degree: 1,
        school: '',
        discipline: '',
        years: 1,
        graduationNo: '',
        degreeNo: ''
      },
      educategorylist: [],
      degrees: []
    }
  },
  components: {
    MyDatePicker
  },
  created() {
    if (this.editable != null) {
      this.isEditable = this.editable
    }
    this.educategorylist = this.$store.state.sysconfigs.educategorylist
    this.degrees = this.$store.state.sysconfigs.FtEducation
  },
  methods: {
    clearEditData() {
      this.editeducation.category = 1,
        this.editeducation.degree = 1,
        this.editeducation.school = '',
        this.editeducation.discipline = '',
        this.editeducation.years = 1,
        this.editeducation.graduationNo = '',
        this.editeducation.degreeNo = ''
    },
    getname(cates, id) {
      for (var index in cates) {
        if (cates[index].id == id) {
          return cates[index].name;
        }
      }
      return ''
    },
    getdegreename(id) {
      return this.getname(this.degrees, id)
    },
    getcategoryname(id) {
      return this.getname(this.educategorylist, id)
    },
    deletetrain(index) {
      this.educations.splice(index, 1)
    },
    deepCopy(o, c) {
      var c = c || {}
      for (var i in o) {
        if (typeof o[i] === 'object') {
          if (o[i].constructor === Array) {
            c[i] = []
          } else {
            c[i] = {}
          }
          this.deepCopy(o[i], c[i])
        } else {
          c[i] = o[i]
        }
      }
      return c
    },
    submit(e) {
      var newtrain = {}
      this.deepCopy(this.editeducation, newtrain)
      this.educations.push(newtrain)
      this.clearEditData()
      this.editVisiable = false
    }
  }
}
</script>
<style scoped>
#furtherEdu{
  min-height: 400px;
}
</style>
